package start.convert;


import com.fasterxml.jackson.databind.json.JsonMapper;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class DtoPoConvertUtils {
    public DtoPoConvertUtils() {
    }

    public static <DTO, PO> DTO convertToDTO(Class<DTO> dtoClass, Object po, Object... params) {
        if (po == null) {
            return null;
        } else {
            Object dto = null;

            try {
                dto = dtoClass.newInstance();
            } catch (Exception var6) {
                var6.printStackTrace();
                throw new RuntimeException("创建DTO对象出错");
            }

            String[] ignoreProperties = null;
            if (params != null && params.length > 0) {
                ignoreProperties = (String[])((String[])params[0]);
            }

            try {
                if (ignoreProperties != null && ignoreProperties.length > 0) {
                    UtilMethod.copyProperties(po, dto, ignoreProperties);
                } else {
                    UtilMethod.copyProperties(po, dto);
                }

                return (DTO) dto;
            } catch (Exception var7) {
                var7.printStackTrace();
                throw new RuntimeException("对象转换出错");
            }
        }
    }

    public static <PO> PO convertToPO(Class<PO> poClass, Object dto, Object... params) {
        if (dto == null) {
            return null;
        } else {
            Object po = null;

            try {
                po = poClass.newInstance();
            } catch (Exception var6) {
                var6.printStackTrace();
                throw new RuntimeException("创建PO对象出错");
            }

            String[] ignoreProperties = null;
            if (params != null && params.length > 0) {
                ignoreProperties = (String[])((String[])params[0]);
            }

            try {
                if (ignoreProperties != null && ignoreProperties.length > 0) {
                    UtilMethod.copyProperties(dto, po, ignoreProperties);
                } else {
                    UtilMethod.copyProperties(dto, po);
                }

                return (PO) po;
            } catch (Exception var7) {
                var7.printStackTrace();
                throw new RuntimeException("对象转换出错");
            }
        }
    }


}